//
//  YYMDTHeaderView.m
//  On The Load
//
//  Created by 我爱的妞 on 15/11/6.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "YYMDTHeaderView.h"
#import "BaseCollectionView.h"
#import "YMAreaModel.h"

@implementation YYMDTHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        self.bgImgView = [[UIImageView alloc] initWithFrame:frame];
        self.bgImgView.image = [UIImage imageNamed:@"foot_mine_photo.jpg"];
        
        [self addSubview:_bgImgView];
    }
    
    return self;
}

- (void)setDataArray:(NSArray *)dataArray{
    
    _dataArray = dataArray;
    NSInteger index = 0;
    CGFloat marin = 15 * SCALEW;
    CGFloat w = (WIDTH - marin * 3) / 2;
    CGFloat h = 15 * SCALEH;
    
    for (YMAreaModel *model in dataArray) {
        
        NSString *text = [NSString stringWithFormat:@"%@ %@", model.name, model.city_num];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        btn.frame = CGRectMake(marin + marin * index + w * index, 5 + h * (index / 2), w, h);
        btn.layer.masksToBounds = YES;
        btn.layer.borderColor = [UIColor whiteColor].CGColor;
        btn.layer.borderWidth = 2;
        btn.layer.cornerRadius = 5;
        
        [btn setTitle:text forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        index++;
        
        [self addSubview:btn];
        
        [self.btnArray addObject:btn];
    }
    
}

- (void)scallImgView:(CGRect)frame{
    NSLog(@"%@", NSStringFromCGRect(frame));
    self.bgImgView.frame = frame;
    //    设置imageView高度改变时宽度也跟着改变
    self.bgImgView.contentMode = UIViewContentModeScaleAspectFill;
}

@end
